package com.his.controller;

import com.his.annotation.RequireRoles;
import com.his.common.Const;
import com.his.common.PageParam;
import com.his.common.Rsp;
import com.his.entity.DoctorAdviceAction;
import com.his.service.DoctorAdviceActionService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * (DoctorAdviceAction)表控制层
 *
 * @author makejava
 * @since 2020-10-23 18:08:13
 */
@Validated
@RestController
@RequestMapping("doctorAdviceAction")
public class DoctorAdviceActionController {
    /**
     * 服务对象
     */
    @Resource
    private DoctorAdviceActionService doctorAdviceActionService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequireRoles(roles = {"doctor", "nurse"}, index = 0)
    @GetMapping("selectOne")
    public Rsp selectOne(@RequestHeader(Const.TOKEN) String token, Integer id) {
        return Rsp.success(doctorAdviceActionService.queryById(id));
    }

    @RequireRoles(roles = {"doctor", "nurse"}, index = 0)
    @PostMapping("insertOne")
    public Rsp insertOne(@RequestHeader(Const.TOKEN) String token, @RequestBody DoctorAdviceAction doctorAdviceAction) {
        return Rsp.success(doctorAdviceActionService.insert(doctorAdviceAction));
    }

    @RequireRoles(roles = {"doctor", "nurse"}, index = 0)
    @GetMapping("selectOneByAdviceId")
    public Rsp selectOneByAdviceId(@RequestHeader(Const.TOKEN) String token, @NotBlank String id) {
        return Rsp.success(doctorAdviceActionService.queryByAdviceId(id));
    }

    @RequireRoles(roles = {"doctor", "nurse"}, index = 0)
    @PostMapping("getAllAction")
    public Rsp getAllAction(@RequestHeader(Const.TOKEN) String token, @RequestBody PageParam<DoctorAdviceAction> pageParam) {
        return doctorAdviceActionService.queryAll(pageParam);
    }

}
